<template>
	<view class="main">
		<view class="card" v-for="item in couponList" :key="item.yhjId">
			<Card :item="item" :type="1" />
		</view>
		<uni-load-more iconType="circle" :status="status" :content-text="contentText" />
	</view>
</template>

<script setup>
import { ref, reactive, onMounted } from 'vue';
import Card from '@/components/card.vue';
import { onLoad, onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app';
import { getCouponList } from '@/api/apiList.js';

// 请求优惠券列表
let queryData = reactive({
	pageNum: 1,
	pageSize: 10,
	yhjType: ''
});
let couponList = ref([]);
const status = ref('no-more');
const getCouponListData = async () => {
	status.value = 'loading';
	const res = await getCouponList(queryData);
	if (res.code == 200) {
		if (res.data.list.length) {
			couponList.value = [...couponList.value, ...res.data.list];
			status.value = 'no-more';
		} else {
			status.value = 'no-more';
		}
	}
};

onPullDownRefresh(async () => {
	uni.showLoading();
	couponList.value = [];
	queryData.pageNum = 1;
	await getCouponListData();
	uni.hideLoading();
	uni.stopPullDownRefresh();
});

onReachBottom(() => {
	queryData.pageNum++;
	getCouponListData();
});

onLoad((option) => {
	queryData.yhjType = option.type;
	getCouponListData();
	uni.setNavigationBarTitle({
		title: option.title
	});
});
</script>

<style lang="scss" scoped>
.main {
	padding: 30rpx;
}
</style>
